#ifndef _RENDER_SYSTEM_H_
#define _RENDER_SYSTEM_H_

#include "engine.h"
#include "opengl/opengl_shader.h"
#include "opengl/opengl_texture.h"

namespace engine
{
    /**
     * RenderSystem 渲染器
     *
     */
    class RenderSystem
    {
    public:
        static RenderSystem *getInstance()
        {
            if (nullptr == renderSystem)
            {
                renderSystem = new RenderSystem();
            }
            return renderSystem;
        }

        void init();
        void render(double time);

        Shader *loadShader(std::string name, const char *vShaderFile, const char *fShaderFile, const char *gShaderFile);
        Shader *getShader(std::string name);
        bool removeShader(std::string name);
        Texture2D *loadTexture(std::string name, const char *textureFile, bool alpha);
        Texture2D *getTexture(std::string name);
        bool removeTexture(std::string name);

        void clear();

        void processInput(GLFWwindow *window);

    protected:
        void resize(int x, int y, int width, int height);
        // void renderMeshs(std::vector<RenderObject::ptr> meshs);
        // void projectObject(Object3D::ptr object);
        // void setProgram(RenderObject::ptr mesh);
        // void setupLights(std::vector<Light::ptr> lights);
        // void setTexture(TextureUnitState::ptr texutre);

    private:
        static RenderSystem *renderSystem;

        RenderSystem();
        ~RenderSystem();
        // RenderSystem(Scene *scene, Camera *camera);

        std::shared_ptr<Scene> _scene; // 场景
        // Camera::ptr camera; //摄像机

        // std::vector<RenderObject::ptr> _mMeshs; //模型
        // std::vector<Light::ptr> _mLights;       //灯光

        std::map<std::string, Shader *> shaders;
        std::map<std::string, Texture2D *> textures;
    };
}
#endif